from .main import GoodsMain
from rest_framework.views import APIView


class GoodsView(APIView):
    good_main = GoodsMain()

    def post(self, request):
        """  添加商品信息  """
        return self.good_main.add_goods(request)

    def get(self, request):
        """  获取商品信息  """
        return self.good_main.search_goods(request)


class GoodsAlterView(GoodsView):
    good_main = GoodsMain()

    def put(self, request, id):
        """ 修改商品信息 """
        return self.good_main.alter_goods(request, id)

    def delete(self, request, id):
        """ 删除商品信息 """
        return self.good_main.delete_goods(id)


class GoodsReduce(APIView):
    """ 商品库存 """
    good_main = GoodsMain()

    def post(self, request, id):
        """ 扣减库存 """
        return self.good_main.pre_reduce_stock(request, id)

class ClearAllCache(APIView):
    good_main = GoodsMain()

    def post(self, request):
        return self.good_main.clear_cache()